#!/bin/bash

#执行此脚本需要api3
#etcdctl version
#export ETCDCTL_API=3


# 原始键的前缀
src_prefix="/Config/pro/ai_call_flow"
# 目标键的前缀
dst_prefix="/Config/dev/ai_call_flow"

# 获取原始前缀下的所有键
keys=$(etcdctl get "$src_prefix" --prefix --keys-only)

# 循环遍历每个键
echo "$keys" | while read -r key; do

    if [ -z "$key" ]; then
          # 忽略空行
          continue
      fi

    # 去除原始前缀，获得相对键路径
    relative_key=${key#$src_prefix}
    # 读取原始键的值
    value=$(etcdctl get "$key" --print-value-only)
    # 构造新的目标键路径
    new_key="$dst_prefix$relative_key"
    # 将值复制到新的键
    etcdctl put "$new_key" "$value"
    echo "Copied $key to $new_key"
done
